'use client'; import { useFormContext, useWatch } from 'react-hook-form'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { FormField, FormItem, FormLabel, FormControl, FormMessage } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { Youtube, CheckCircle2, XCircle } from 'lucide-react'; import { memo } from 'react'; import { cn } from '@/lib/utils'; const isValidYoutubeUrl = (url: string) => { if (!url) return true; const youtubeRegExp = /^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?([a-zA-Z0-9_-]{11})$/; return youtubeRegExp.test(url); }; const getYoutubeEmbedUrl = (url: string) => { if (!url) return ''; const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#&?]*).*/; const match = url.match(regExp); const videoId = (match && match[2].length === 11) ? match[2] : null; return videoId ? `https://www.youtube.com/embed/${videoId}` : ''; }; export const VideoSection = memo(function VideoSection() { const { control } = useFormContext(); const videoUrl = useWatch({ control, name: 'videoUrl' }) || ''; const embedUrl = getYoutubeEmbedUrl(videoUrl); const isValid = isValidYoutubeUrl(videoUrl); return (
Video Promocional

Añade un video de YouTube para mostrar lo mejor de tu plan.

( URL del Video de YouTube
{videoUrl && (
{isValid ? : }
)}
)} />

Pega la URL completa de un video de YouTube. El reproductor aparecerá a la derecha para que puedas previsualizarlo.

{embedUrl && isValid ? (